package designpattern.proxy.findGirlFriend.dynamic;

import designpattern.proxy.findGirlFriend.IPeople;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 刘牌
 * @Date: 2021/12/17/11:11
 * @Description:
 */
public class MikeyProxyTeacher implements InvocationHandler {

    private IPeople people;

    public IPeople getPeopleInstance(IPeople people){
        this.people = people;
        return (IPeople) Proxy.newProxyInstance(people.getClass().getClassLoader(),people.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("mikey老师：我现在开始帮广大单身网友找女朋友");
        Object response = method.invoke(people,args);
        System.out.println("mikey老师：为单身网友找到女朋友");
        return response;
    }
}
